<?php
//---------------------------------------------------------------------------------------------------------------------------
    include_once($config['app_dir'] . '/includes/object.class.php');
    include_once($config['app_dir'] . '/includes/db.class.php');
    //-------------------------------------------------------------------------------------------------------------------
    class objAuxiliary {
            protected $items;
            protected $valid;
            private $db;

        function __construct() {
        } //constructor objSimpleList

       public function getNumOfFiles($dir) {
            if (is_dir($dir)) {
    			if ($dh = opendir($dir)) {    				$cntr = 0;
        			while (($file = readdir($dh)) !== false) {
            			echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
            			$cntr++;
        			}
       				closedir($dh);
       			}
    		}

    		return $cntr;
    	}

    	public function getRandomFromRange($min, $max) {
            return rand($min, $max);
    	}


    	public function getPairIDTF($tfAbbr, $pairCode) {    		$tradeID = $this->convertTimeframeFromAbbr($tfAbbr).$pairCode;
            return $tradeID;
    	}


    	public function convertTimeframeFromAbbr($tfAbbr) {    		switch ($tfAbbr){    			case "mn":
    			case "MN":
    				$tfMin = 43200;
    				break;    			case "w1":
    			case "W1":
    				$tfMin = 10080;
    				break;    			case "d1":
    			case "D1":
    				$tfMin = 1440;
    				break;    			case "h4":
    			case "H4":
    				$tfMin = 240;
    				break;
    			case "h1":
    			case "H1":
    				$tfMin = 60;
    				break;
    			case "m30":
    			case "M30":
    				$tfMin = 30;
    				break;
    			case "m15":
    			case "M15":
    				$tfMin = 15;
    				break;
    			case "m5":
    			case "M5":
    				$tfMin = 5;
    				break;
    			case "m1":
    			case "M1":
    				$tfMin = 1;
    				break;
    		};
    		//$tfMin = 240; // override because only H4 timeframe is currently supported
            return $tfMin;
    	}


		public function getSystemShortName($systemID) {            $db = objDataBase::GetInstance();
            $rs = $db->handler->GetRow("SELECT ShortName FROM fa_systems WHERE SystemID=?", array($systemID));
    		$systemSN = $rs['ShortName'];

            return $systemSN;
    	}


    	public function getPagingData ($totalRecords,$recordsPerPage) {
	        $RPPdivision = $totalRecords % $recordsPerPage;
	        $rawPages = intval($totalRecords / $recordsPerPage);
	        $totalPages = ($RPPdivision == 0) ? $rawPages : $rawPages+1;

	        $pagesArr = array();
	        $currentIndex = 0;

	        for($i=0; $i<$totalPages; $i++){
	         	$pagesArr[$i]['label']['start'] = $currentIndex+1;
	         	$pagesArr[$i]['label']['end'] = $currentIndex + $recordsPerPage;
	         	$pagesArr[$i]['param']['start'] = $currentIndex;
	         	$pagesArr[$i]['param']['end'] = $currentIndex + $recordsPerPage + 1;
	         	$currentIndex = $currentIndex + $recordsPerPage;
	        }

        return $pagesArr;


      } //getPagingData


    } //class objAuxiliary
//---------------------------------------------------------------------------------------------------------------------------

?>
